package model;

import java.util.Enumeration;
import java.util.Vector;

import dao.EmployeeDAO;

public class ListEmployee {
	private EmployeeDAO employeeDAO ;
	private Vector employee;
	private int id = 0;

	public ListEmployee() {
		employee = new Vector();
	}

	public void connect() {
		employeeDAO = new EmployeeDAO();
		employee = employeeDAO.getListemployee();
	}

	public int getID() {
		return id;
	}

	public void addEmployee(int employee_id, String fname, String lname,
			String uname, String pwd, int pos) {
		Employee newemp = new Employee(id, fname, lname, uname, pwd, pos);

		employee.addElement(newemp);
	}

	public void addEmployee(Employee e) {
		Employee e1 = new Employee(id, e.getFirstname(), e.getLastname(),
				e.getUsername(), e.getPassword(), e.getPosition());
		id++;
		employee.addElement(e1);
	}

	public int employeeLogin(String uname, String pwd) {
		Enumeration emp = employee.elements();
		while (emp.hasMoreElements()) {
			Employee each = (Employee) emp.nextElement();
			if (uname.equals(each.getUsername())) {
				if (pwd.equals(each.getPassword()))
					return each.getID();
				else
					return -1;
			}
		}
		return -1;
	}

	public Employee getEmployeeByID(int id) {
		Enumeration emp = employee.elements();
		while (emp.hasMoreElements()) {
			Employee each = (Employee) emp.nextElement();
			if (id == each.getID()) {
				return each;
			}
		}
		return new Employee();
	}
}